package com.example.black.myapplication.wrap;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.example.black.myapplication.MyAdapter;
import com.example.black.myapplication.R;
import com.example.black.myapplication.WrapRecycleView;

import java.util.ArrayList;
import java.util.List;


public class WrapViewActivity extends AppCompatActivity {
    private WrapRecycleView rv;
    private List<String> list = new ArrayList<>();
    private Button button;
    private Button button2;
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        for (int i = 0; i < 20; i++) {
            list.add(String.valueOf(i));
        }
        initWrapView();
    }

    /**
     * 初始化 wrapRecycleView 的调试代码
     */
    private void initWrapView() {
        rv = findViewById(R.id.rv);
        TextView textView = new TextView(this);
        textView.setText("测试header");
        textView.setGravity(Gravity.CENTER);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT
                , RecyclerView.LayoutParams.WRAP_CONTENT);
        textView.setLayoutParams(params);
        //rv.addHeaderView(textView);
        TextView textView1 = new TextView(this);
        textView1.setText("测试header");
        textView1.setGravity(Gravity.CENTER);
        textView1.setLayoutParams(params);

        //rv.addFooterView(textView1);
        //rv.setLayoutManager(new StaggeredGridLayoutManager(3, LinearLayoutManager.VERTICAL));//瀑布流不适合增加,修改 性能很差？
        rv.setLayoutManager(new GridLayoutManager(this,3
                , LinearLayoutManager.VERTICAL,false));
        //    rv.setLayoutManager(new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false));
        adapter = new MyAdapter(list,this);
        rv.setAdapter(adapter);

        //rv.addItemDecoration(new MyItemDecoration(this,MyItemDecoration.GRID));
        //rv.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
      //  rv.addItemDecoration(new DividerGridViewItemDecoration(this));
        button = findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                adapter.addData();
            }
        });
        button2 = findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               adapter.removeData(0);
            }
        });
    }

}
